#!/usr/bin/env python
#coding=utf8

import requests
from lxml import etree

host=r'https://m.zhihu.com/login/email'
url=r'https://m.zhihu.com'
loginurl=r'https://www.zhihu.com/#signin'

html=requests.get(loginurl).content
sel=etree.HTML(html)
_xsrf=sel.xpath('//input[@name="_xsrf"]/@value')[0]
#print _xsrf

postdata={
    "_xsrf": _xsrf,     # 登陆页面的随机变量，会写入cookie中
    "password":"XXXXXXXXXXXX",      # password
    "remember_me":"true",
    "email":"XXX@XXXX.XXX"          # login email
}
headers={
    "Host":"m.zhihu.com",
    "User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0",
    "Accept":"*/*",
    "Accept-Language":"zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
    "Accept-Encoding":"gzip, deflate, br",
    "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
    "X-Requested-With":"XMLHttpRequest",
    "Referer":"https://m.zhihu.com/",
    "Content-Length":"98",
    #"Cookie": '',      #header中的cookie已删除
    "Connection":"keep-alive",
    }

import json
s=requests.Session()
response=s.post(host,postdata,headers=headers)
d_json= response.content
d=json.loads(d_json)
print d['msg']
#response=s.get(url)
#print response.content